package com.example.project.controller;

import com.example.project.pojo.Student;
import com.example.project.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping("/search_student")
    public String index(HttpSession session){
        List<Student> studentLostAll = studentService.GetStudentAll();
        session.setAttribute("studentLostAll",studentLostAll);
        return studentLostAll.toString();
    }

    @RequestMapping("/addStudent")
    public String addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return "";
    }

    @RequestMapping("/updateEval")
    public String updateEval(@RequestBody Student student){
        studentService.updateEval(student);
        return "";
    }

    @RequestMapping(value = "/deleteStudent")
    public String deleteStudent(int id){
        studentService.deleteStudent(id);
        return "";
    }

}
